﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IHISCETeim.BLL;
using IHISCETeim.Library;
using IHISCETeim.Model;
using System.Data;
using System.Text;

namespace IHISCETeim.Web.MachineSys.FTradeModel
{
    public partial class FTradeReceivablesEdit : PageBase
    {
        protected override string DWZRef
        {
            get
            {
                return "FTradeReceivablesListEasyUI";
            }
        }

        protected override Permission[] PowerKey
        {
            get
            {
                return new Permission[] { Permission.修改 };
            }
        }

        protected int FTradeID
        {
            get
            {

                return GetRequestValue<int>("FTradeID", 0);
            }
        }

        private FTradeReceivablesInfo _objFx = null;

        protected FTradeReceivablesInfo obj
        {
            get
            {
                if (_objFx == null)
                    _objFx = FTradeReceivablesController.GetByFTradeID(FTradeID);
                return _objFx;
            }
        }


        #region 页面方法
        /// <summary>
        /// 获取所有销售类型SELECT　项
        /// </summary>
        /// <param name="XiaoShouLeiXing"></param>
        /// <returns></returns>
        protected string GetXiaoShouLeiXing(string XiaoShouLeiXing)
        {
            List<FTradeSaleTypeConfigInfo> list = FTradeSaleTypeConfigController.GetAll();
            StringBuilder sb = new StringBuilder();
            foreach (FTradeSaleTypeConfigInfo itm in list)
            {
                sb.AppendFormat("<option value=\"{0}\" {1}>{0}</option>", itm.XiaoShouLeiXing, itm.XiaoShouLeiXing == XiaoShouLeiXing ? "selected" : "");
            }

            return sb.ToString();
        }
        
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {
            if (GetRequestValue<string>("ajaxmethod", "") == "edit")
            {
                addmenu();
                
            }
        }
        private void addmenu()
        {
            FTradeReceivablesInfo objTrade = Request.SerializableObject<FTradeReceivablesInfo>();
           // objTrade.YueCuXiaoJinE = 0 - objTrade.YueCuXiaoJinE;
           
            bool msg = FTradeReceivablesController.Update(objTrade);

            AddLog(Permission.修改, obj, objTrade);

            if (msg)
                SuccessJson("修改成功");
            else
            {

                ErrorJson("修改失败");
            }
        }

        private string GetXiaoShouLeiXingExConfig(string XiaoShouLeiXing)
        {
            List<string> PageConfig = new List<string>();
            PageConfig.Add("PageConfig_QiShu");
            PageConfig.Add("PageConfig_QiShuType");
            PageConfig.Add("PageConfig_JinE");
            StringBuilder sb = new StringBuilder();
            switch (XiaoShouLeiXing.Trim())
            {
                case "全款":
                case "首付代垫":
                case "置换分期":
                    return "";
                    break;
                case "短期分期":
                case "置换加分期":
                    foreach (string itm in PageConfig)
                    {
                        sb.AppendFormat("{0}|{1}", itm, GetRequestValue<string>(itm, ""));
                    }
                    return sb.ToString();
                    break;
                default:
                    return "";
                    break;
            }

            return "";
        }
    }
}